home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 10 / cnews010.nws
Text File  |  1988-08-15  |  55KB  |  1,139 lines

  1.  
  2. *------------------------------------------------------------------------*
  3. |                                                                        |
  4. |   C News - International C Newsletter, Compiler review, and            |
  5. |            Tutorial.                                                   |
  6. |                                                                        |
  7. *------------------------------------------------------------------------* 
  8.  Volume 1, Number 10                                            9 Aug 1988 
  9.  
  10.  
  11.  Editor        |       Editor's Corner: The Heap  .................... 1   
  12.  Barry Lynch   |         by Barry Lynch 
  13.                |       
  14.  Australian    |       Magazines: The Latest Crop  ................... 2
  15.  Office:       |         by Barry Lynch
  16.  David Nugent  |         
  17.                |       Book Reviews: 
  18.                |       QuickC Programming for the IBM ................ 4 
  19.                |         Reviewed by Barry Lynch   
  20.                |   
  21.                |       Database Design  .............................. 6 
  22.                |          by Arnie Cherdak  
  23.                |  
  24.                |
  25.                |       Latest PD/Commercial Software Release  ....... 19
  26.                | 
  27.                |       Article Submission Standards  ................ 20
  28.                | 
  29.                |       Address's    ................................. 21
  30.                | 
  31.                |       Index   ...................................... 22
  32.                | 
  33.                |       Distribution Points   ........................ 24
  34.                |  
  35.                |       User Response Form  .......................... 25
  36.                |
  37.                |
  38.                |
  39.                |       C News is an Electronic Journal published by the  
  40.                |       C BBS in Burke, VA Bi-Monthly.  All rights are 
  41.                |       reserved, and all opinions expressed are of the 
  42.                |       authors and any damage sustained, either physically 
  43.                |       or financially via use of the routines in this 
  44.                |       journal are at the sole expense of the reader. 
  45.                | 
  46.                | 
  47.       C News 1-10                 Page 1                   09 Aug 1988  
  48.   
  49.       ================================================================  
  50.       The Heap:  Messages from the editor    
  51.       ================================================================  
  52.   
  53.       COMPUTER AIDED SOFTWARE ENGINEERING: Some thoughts ....
  54.   
  55.            One area of programming that has always interested me, is
  56.       computer aided software engineering.  I suppose what I am really
  57.       looking for is a software tool that helps me to automate the design, 
  58.       coding and maintenance of my code/applications.  This need is not 
  59.       just for the PC world either, but the mini and mainframe world as
  60.       well.  According to Datamation < an DP industry trade journal >, the 
  61.       largest portion of a corporate MIS's group time and resources is 
  62.       spent on maintaining software that is in production.  This I can
  63.       agree on, from first hand experience.
  64.  
  65.            I work for a large corporation that has annual sales over the
  66.       1 Billion mark.  I work in an Engineering group that is responsible
  67.       designing, planning, projectizing, implementing, and maintaining 
  68.       application software on minis and mainframes.  The biggest problem
  69.       we face is: getting ALL of the functionality we request in a release,
  70.       and getting releases on a timely basis.  Both of the problems are
  71.       directly related to the amount of work that is requested from the
  72.       Corporate MIS groups, and the nature of the business we are in.
  73.  
  74.            Maintaining code is difficult, because of the myriad of
  75.       relationships the various modules in an application have with other
  76.       seemingly unrelated applications from other organizations.  What is
  77.       needed is the ability to link all applications together, so that
  78.       changes in one that affect others, are reported on, and acted upon
  79.       at the same time.  What generally happens is that one department
  80.       will make a change, that another affected department finds out about
  81.       when the application starts to crash.  Thus necessitating emergency
  82.       coding by the affected group, thus delaying other projects in
  83.       progress etc.
  84.  
  85.            I feel that the maintainability of code is so important that
  86.       a message area here at the C BBS - Number 22 - has been dedicated to
  87.       the subject.  Other the coming months we hope to begin to understand
  88.       this field more.  If you are interested or involved in this field
  89.       we would like to hear from you.
  90.  
  91.       HONEYMOON..
  92.  
  93.            As some of you know I will be getting married on the 27th of
  94.       August.  Therefore, the C BBS will be on autopilot from the 27th
  95.       to the 10th of September.  So if you leave me a message in that
  96.       time, do not get offended if I do not answer right away.  I will
  97.       not be taking a PC with me or have access to one.  So enjoy..
  98.  
  99.  
  100.     
  101.       C News 1-10                Page 2                    09 Jul 1988
  102.  
  103.       ================================================================ 
  104.       MAGAZINE Reviews:  by Barry Lynch 
  105.       ================================================================ 
  106.  
  107.       Magazine:  Micro Cornucopia
  108.       Issue: No. 43  Sept - Oct 88
  109.       Publisher: Micro Cornucopia Inc
  110.                  155 NW Hawthorne, Bend OR 97701
  111.       
  112.       Subject:  The Grass-Roots side of the PC World.
  113.  
  114.       This issue of MC is dedicated to Database's.  <Funny how this
  115.       issue of C News is covering the same subject!>  One of the
  116.       things that I like about MC is it's approach - grass roots. MC
  117.       reminds me of what Byte used to be in the old days - informative,
  118.       and interesting.  Quite frankly it is one of the few magazines
  119.       that I look forward to getting.
  120.  
  121.       This issue contains:
  122.  
  123.        -  Accessing Dbase III records from Turbo Pascal.
  124.        -  Building a C Database.
  125.        -  Selecting a DBASE III Compatible Compiler
  126.        -  Working with Paradox
  127.        -  Build a Pascal Database.
  128.        -  Designing Custom PC Cards.
  129.  
  130.       For those of you that read the FidoNet C_Echo on a regular basis,
  131.        you will recognize the name of Scott Ladd.  Scott writes the
  132.        "C'ing Clearly" column for MC, and does an excellent job of 
  133.        keeping on top of the latest product releases, bug reports.  This
  134.        issue of MC, he digs into ANSI C some.
  135.  
  136.        Check out MC it is worth the yearly $18 fee for 6 issues.  A tad
  137.        more expensive than the other magazines that are available.  But
  138.        at least you get the feeling that the folks in Oregon like what
  139.        they are doing, and want to hear from us users.
  140.  
  141.       C News 1-10               Page 3                    09 Aug 1988
  142.  
  143.       ================================================================ 
  144.       MAGAZINE Reviews:  by Barry Lynch 
  145.       ================================================================ 
  146.  
  147.       Magazine:  Microsoft Systems Journal
  148.       Issue: Vol 3. No 4.  July 1988
  149.       Publisher: Microsoft Corporation
  150.                  666 Third Avenue, New York, NY 10017
  151.         
  152.       Subject:  Articles associated with Microsoft Products.
  153.  
  154.       This issue of MSS includes the following articles:
  155.  
  156.        - DARWIN(tm) A Merrill Lynch Microsoft Windows Application
  157.        - Codeview(tm) for Windows.
  158.        - OS/2 Graphics Programming Interface.
  159.        - MSC MASM 5.1
  160.        - Color mixing principles and how color works in the raster 
  161.          video model.
  162.        - Creating user defined controls for your own Windows
  163.          applications.
  164.        - SQL server brings DBMS to OS/2...
  165.  
  166.       One of the problems with this publication is it's nasty habit
  167.       of taking Microsoft press releases and making articles out of
  168.       them.  However, in among the chaff are a few grains of wheat 
  169.       worth digging for.  If you are serious about Windows or OS/2
  170.       programming, then MSS is a good resource tool to have.  
  171.  
  172.       C News 1-10                Page 4                    09 Aug 1988
  173.  
  174.       ================================================================ 
  175.       MAGAZINE Reviews: By Barry Lynch
  176.       ================================================================ 
  177.  
  178.        Magazine:  Dr. Dobb's Journal of Software Tools
  179.        Issue: #142 August 1988
  180.        Publisher: M&T Publishing Inc.
  181.                   501 Galveston Drive
  182.                   Redwood City, CA 94063
  183.  
  184.        Subject:  Articles associated with Programming.
  185.  
  186.       First, the August issue of Dr. Dobb's is the annual C issue,
  187.        and is a must for all C programmers.  Second, Dr. Dobb's is
  188.        still one of the best programming magazines around and occupies
  189.        a permanent home of my book shelf. <Labeled Magazine holders
  190.        and all..>   
  191.  
  192.        This issue of DDJ includes the following articles:
  193.  
  194.       - C Compiler Review
  195.        - Find that Function
  196.        - Automatic Module Control in C
  197.        - A tool for Secret Key Crytography
  198.        - C Programming
  199.        
  200.        and others.   
  201.  
  202.        This issue is a milestone of sorts, Allen Holub has been the
  203.        C Programming columnist for as long as I can remember.  He has
  204.        stepped down from that position and been replaced by Al Stevens,
  205.        of 'Programming TSR's ' fame.  It will be interesting to see
  206.        where Mr. Steven's takes the column.  At any rate, DDJ is a 
  207.        magazine that all programmers should read on a regular basis.
  208.        Some of the c source that has appeared in Dr. Dobb's has been
  209.        published in a series of Books by M&T Press.  These are excellent
  210.        Intermediate-to-Advanced books and they are highly recommended.
  211.        
  212.  
  213.  
  214.  
  215.       C News 1-10                Page 5                    09 Aug 1988
  216.  
  217.       ================================================================ 
  218.       BOOK REVIEW'S: By Barry Lynch
  219.       ================================================================ 
  220.  
  221.       Title: QuickC Programming for the IBM
  222.       Author: Carl Townsend
  223.       ISBN Number: 0-672-22622-7
  224.       Publisher: Howard W. Sams and Company
  225.                  4300 West 62nd Street
  226.                  Indianapolis, Indiana 46268
  227.       
  228.            The last thing I needed - and my checkbook - was to buy
  229.       another computer book.  For some reason If I do not buy at least
  230.       one book a month, I feel like I am not keeping up with this
  231.       crazy lunacy called the Computer Biz.. Not that I read all of the
  232.       books I own, but you known what I mean.
  233.  
  234.           This is a book aimed at beginning users that use QuickC, hence
  235.       the title.  But, Mr. Townsend does something that I wish other
  236.       authors would do as well.  He provides a complete application in
  237.       source that he uses to explain the C language.  The application is
  238.       a Mailing List program, that utilizes: Menus, a Database, and some   
  239.       reporting capabilities.  I always felt that learning by example 
  240.       was one of the best ways to learn a subject.  Mr. Townsend has done,
  241.       a good job of just that.  If you have just bought QuickC, and have
  242.       thumbed through the manuals that Microsoft gave you.  Go out and
  243.       get a copy of this book, and sit down and relax.  This is an
  244.       excellent beginner's book.
  245.  
  246.       C News 1-10                Page 6                    09 Aug 1988
  247.  
  248.       ================================================================ 
  249.       DATABASE IN C: By Arnold Cherdak
  250.       ================================================================ 
  251.       
  252.            I never paid a lot of attention to the subject of DATABASE.
  253.       It seemed that all I needed to know was how to run dBase II or
  254.       III -- it didn't seem to matter -- in order to satisfy my fairly
  255.       simple needs for putting some information together and then 
  256.       searching, sorting, and examining as required.  It wasn't until I
  257.       needed to do things with database files that were out of the 
  258.       ordinary that I became aware that there was more to databases than
  259.       sequential files.
  260.       
  261.            A proper discussion of the subject of database could fill
  262.       volumes and frequently has.  In this article, I attempt merely to 
  263.       point out some of the subject matter of database technology and to
  264.       focus on some of the more elemental aspects of programming for 
  265.       database using C.  Lest you think I'm going to go off the deep end
  266.       programming exotic and elaborate structures, be aware that I like
  267.       to do things as simply as I can and that I'll use a ready made
  268.       solution to the difficult part, a shareware package that takes care
  269.       of the files and indexes and all that stuff that will allow me to
  270.       focus more on the essence of the problem.  This has an added
  271.       advantage in that it will make this article easier to write and
  272.       easier to read with less obscure detail.  Let's get on with it.
  273.       
  274.           Starting from the top...a database is a collection of
  275.       information, somehow related.  A Database Management System is a
  276.       collection of programs that is used to search, sort, and examine
  277.       that database.  Simple so far...but let's go on.  
  278.       
  279.           Much of the software technology centered around databases is 
  280.       associated with ways in which information can be extracted from the
  281.       data.  Structured Query Language or SQL is the latest and greatest
  282.       approach to programming searches of a large class of databases. 
  283.  
  284.           Those of you who have experienced dBase may remember the LOCATE
  285.       command that serves a similar purpose.  Many database manager
  286.       software packages offer a selection of subroutines (for the 
  287.       FORTRANners among us) that can be linked with users' programs to
  288.       search the database for the information of interest to the user. 
  289.       More about searching and ways to do it, later.       
  290.  
  291.          A closely related subject to searching for information is
  292.       displaying the information resulting from the search.  Although
  293.       it's considered by some to be a more mundane aspect of database
  294.       technology, the report probably commands more attention by the
  295.       database user and by the programmer than most other aspects.  The
  296.       user interface, too, gets a lot of attention from the programmer
  297.       as it does in most other types of software.
  298.  
  299.  
  300.       C News 1-10                Page 7                    09 Aug 1988
  301.  
  302.       ================================================================ 
  303.       DATABASE IN C: By Arnold Cherdak
  304.       ================================================================ 
  305.  
  306.       These two aspects of database software are subjects that are too
  307.       big and important to be discussed briefly so I won't even begin. 
  308.       I'll leave them for a future article.
  309.       
  310.            At a lower level of detail, frequently hidden from the user,
  311.       is the fundamental structure of the database which includes the 
  312.       organization of the data and the basic mechanisms used to enter
  313.       data into the database and to access that data.  Since there is 
  314.       generally more data in a database than can be held in primary
  315.       memory at one time and the data is generally required to be non-
  316.       volatile, the database consists of one or more files stored on
  317.       secondary memory (disk).  Databases can be distributed far and
  318.       wide and accessed by way of complex data communications means.
  319.  
  320.            However, this approach is not all that common and a database
  321.       located at a single location is the rule.  Certainly, this is the
  322.       case for the small, PC-based databases we consider here.         
  323.  
  324.            Database files can have a wide range of forms.  At one end of
  325.       the spectrum are complex files containing several segments that
  326.       make up the entire database including directories, headers, indexes,
  327.       and the data.  These complex files can even be organized as trees
  328.       with pointers to adjacent records (i.e., tree nodes) in the tree
  329.       structure contained in each record.  At the other end are simple,
  330.       sequential or "flat" files with uniform records.  DBase III, for
  331.       example, is somewhere in the middle of the complexity spectrum with
  332.       a two-segment data file containing a description of the data records
  333.       at the front followed by uniform data records and a separate file
  334.       containing an index.       
  335.  
  336.            Depending upon the nature of the database management software,
  337.       there can be one or more files that make up the database.  The 
  338.       simplest case has the file composed of fixed size records, each
  339.       record composed of fixed size fields with the field being the
  340.       smallest element of data in the database.  Indeed, if we consider
  341.       the database, itself as a file for our present purposes, the art
  342.       of database programming is really the art of programming searches
  343.       for the information contained in the data file.  This is the subject
  344.       of the rest of this article.
  345.       
  346.       
  347.                   DATABASE 101 -- Linear Searching
  348.       
  349.            Let's continue with the simplest case.  Suppose we had a list
  350.       (file) of names and addresses for a small community of about 200
  351.       families.  Furthermore, suppose we wanted to have a list of families
  352.       living on Main Street.  A very simple way to obtain that list is to
  353.       visually examine the list of all the families from beginning to end,
  354.       C News 1-10                Page 8                    09 Aug 1988
  355.  
  356.       ================================================================ 
  357.       DATABASE IN C: By Arnold Cherdak
  358.       ================================================================ 
  359.  
  360.       one family (record) at a time and to write down the family data
  361.       for each family satisfying the criterion that its street name was
  362.       Main Street.  This is not a wonderfully sophisticated way to get
  363.       the information we want but it certainly is effective.  
  364.       
  365.            I just described a search method that could be programmed in
  366.       C or in some other programming language to search through a file
  367.       containing the family records to create a printed report.  The
  368.       process I went through is as follows:
  369.       
  370.             1)   Open the file to the first record.
  371.             2)   Look at the street name for the record in view.           
  372.             3)   If the street name is Main Street, copy the record        
  373.                  contents to a list.
  374.             4)   If there are no more records, close the file and quit.    
  375.             5)   Otherwise, get the next record.
  376.             6)   Go to step 2 and repeat the process.
  377.       
  378.            For those of you who haven't written such a linear search
  379.       program before, take the time to write a computer program to execute
  380.       these 6 steps.  Use the data file, FAMILIES.DAT, included with this
  381.       issue of CNEWS.  You could use the printer to display your list or
  382.       have your program create another file containing the Main Street
  383.       Report.  The record structure in the data file is as follows:
  384.       
  385.                     struct {
  386.                            char name[25];
  387.                            char street[25];
  388.                            char street_number[10];
  389.                            char other_data[68];
  390.                            } family;
  391.       
  392.            Note that there are 191 records in the file and there are 12
  393.       families that reside on Main Street.  Oh, yes, I almost forgot.
  394.       The City Council was very budget conscious last summer when this
  395.       file was created and they employed a high school student who was
  396.       given the job to create this file.  The student hadn't taken the 
  397.       first course in typing yet and, as a result, the fields in the
  398.       file aren't as neat as they could have been.  You may want to spend
  399.       a little time writing defensive code to be able to read the fields
  400.       reliably.  Sorry about that but the database business IS full of
  401.       things like messy data. <GRIN>
  402.       
  403.  
  404.  
  405.  
  406.  
  407.  
  408.       C News 1-10                Page 9                    09 Aug 1988
  409.  
  410.       ================================================================ 
  411.       DATABASE IN C: By Arnold Cherdak
  412.       ================================================================ 
  413.  
  414.   
  415.                         DATABASE 201 -- Indexes
  416.       
  417.             Well, that's pretty good if all you want to do is generate
  418.       a Main Street List from a 200 record file.  What if you wanted to
  419.       do some more complex things, say, create a sorted listing or work
  420.       with a file having more records, perhaps several thousand records? 
  421.       What if the records are significantly larger?  As the database gets
  422.       bigger, it takes longer and longer to do things with it and if you're
  423.       like me you don't have the fastest cpu and hard disk in town.  There
  424.       has to be a better way, a faster way to get what you want from the
  425.       database than to read it record-by-record and search each record for
  426.       the strings or numbers you want.  There is a better way, it's called
  427.       indexing.
  428.       
  429.            The idea of indexing is fairly straightforward.  Create a file  
  430.       containing index strings or keys that are created from the database
  431.       record fields that you would use during a linear search to decide
  432.       whether you had reached a desired record.  For the Main Street
  433.       Search, you might want to use the street name field as the key.  The
  434.       index file record, then would consist of two fields, the key and the
  435.       record number of the database record that the key came from.  The
  436.       index file would then be much smaller than the database file; having
  437.       the same number but much smaller records.  It would then take much
  438.       less time to manipulate the index file.  When the index is searched
  439.       and a desired key is found, the database record can then be accessed
  440.       immediately using the record number from the index multiplied by the
  441.       record size to get the offset into the database file where the
  442.       desired record begins.  DOS file positioning commands can then be
  443.       used to go directly to the desired record. Alternatively, you can use
  444.       the C function, ftell(), to obtain a pointer to the start of each
  445.       record before it's read.
  446.       
  447.           Please understand, if you have a specific item you're looking
  448.       for and you only want to do it one time, you may want to do just the
  449.       linear search through the database file because, to create an index,
  450.       you need to read through the file at least one time anyway.  The
  451.       index to a database is useful if you are going to access the database
  452.       numerous times and search for more or less randomly specified values
  453.       of the index. 
  454.       
  455.           There are other advantages to using the index file.  It can be 
  456.       sorted to reduce the search time still more.  If you sort 
  457.       alphabetically and search for Main Street, the search is over when
  458.       the street names beginning with 'M' have been exhausted.  Adding full
  459.       records to the database can be done chronologically at the end of the
  460.       database file.  When the new index file records are added to the
  461.       index file, it takes a lot less time to re-sort the index file than
  462.       C News 1-10                Page 10                   09 Aug 1988
  463.  
  464.       ================================================================ 
  465.       DATABASE IN C: By Arnold Cherdak
  466.       ================================================================ 
  467.  
  468.       the database file.  Similarly, more than one index file can be
  469.       created to serve different purposes while keeping the chronological
  470.       sequence of the database intact.       
  471.  
  472.            I haven't said anything about the organization of the index
  473.       file.  It can be a flat file in the simplest case or, to make the
  474.       searches faster, it can be organized in other ways with tree
  475.       organization probably the most often used.  Index organization is
  476.       discussed below.
  477.  
  478.                   DATABASE 301 -- More Sophisticated Ways
  479.       
  480.            There are ways to reduce the amount of index manipulation
  481.       required by linear searching.  Some of these include Indexed
  482.       Sequential searching, tree searching, binary searching, and hashing
  483.       to name just a few.
  484.       
  485.            Indexed Sequential searching is a technique in which the 
  486.       database is sorted and the index contains only a fraction (about
  487.       10 percent) of the number of records that exist in the database.
  488.       Finding a record is done by locating a key close to the desired
  489.       key in the index and performing a linear search in the database
  490.       through just a small number of records near the key record.  This
  491.       is very effective where the number of database records is very
  492.       large and manipulation of a regular index file would be too time
  493.       consuming or the full index won't fit in available memory.
  494.  
  495.            Hashing is an approach that attempts to minimize the number of
  496.       comparisons made of the desired key with the keys in the index in
  497.       performing the search.  A single access is the goal of hashing.
  498.       With this technique, a Hash Function converts the desired key to
  499.       an integer value which is interpreted as a table or array index 
  500.       or as an address.  The value at that index or address is then a
  501.       pointer to the desired data record or even the record itself. 
  502.       More on Indexed Sequential searching and Hashing in a future
  503.       article.
  504.             
  505.           Binary searching permits rapidly arriving at the index record
  506.       when using an index that is sorted in order of the key value. 
  507.       (NOTE that even string keys have a "value" when compared with other
  508.       string keys.  See the string comparison function descriptions in your
  509.       programming language manual).  
  510.       
  511.            Finding the desired database record is done by comparing the 
  512.       desired key with the key at the center of the index file.  If there's
  513.       a match, go right to the database record.  If the desired key is
  514.       larger than the center index key, look at the index key half way
  515.       between the current index file location and the end of the index
  516.       C News 1-10                Page 11                   09 Aug 1988
  517.  
  518.       ================================================================ 
  519.       DATABASE IN C: By Arnold Cherdak
  520.       ================================================================ 
  521.  
  522.       file.  If the desired key is smaller, look at the index key half
  523.       way toward the beginning of the index file.  Continue this process
  524.       until the desired index key is found or until you have gone through
  525.       the entire file unsuccessfully in which case the search has failed. 
  526.       The binary search function looks like  Listing 1.
  527.       
  528.             -------------------------------------------------
  529.                  LISTING 1.  BINARY SEARCH FUNCTION
  530.  
  531.       char *k(x);    /* returns pointer to key for record x */       
  532.       void binary_search(long n, char *key)  
  533.       {                          /* n = number of records in list */      
  534.       long low,mid,hi,x;         /* key is desired record key */ 
  535.       int found;
  536.       
  537.       found = FALSE;
  538.       low = 1;                        /* beginning of list        */ 
  539.       hi = n;                         /* end of list              */      
  540.       while(low<=hi && !found) 
  541.           {
  542.           mid = (low + hi) / 2;       /* calculate middle of list */       
  543.           if(strcmp(key,k(mid)) == 0) /* k(x) looks up key value  */       
  544.           found = TRUE;            /* match is found           */
  545.  
  546.           else                 /* no match, larger or smaller key */
  547.  
  548.              if(strcmp(key,k(mid))<0) 
  549.                 hi = mid - 1;         /* key is < middle key      */       
  550.           else
  551.                 low = mid + 1;        /* key is > middle key      */       
  552.        } /* end while */
  553.       
  554.        if(found)                     /* return record number found */      
  555.        return(mid);                  /* success -- record found */         
  556.           else
  557.        return(0);          /* search failed -- record not found */
  558.  
  559.        } /* end binary_search */
  560.       
  561.        NOTE: 1.If the index list is in a file, then function k(x) will
  562.                have to access that file to get the desired key values.
  563.  
  564.              2.It is assumed that the index list is sorted in ascending
  565.                order with index record n greater than index record 1.
  566.                 -------------------------------------------------         
  567.        
  568.    
  569.  
  570.       C News 1-10                Page 12                   09 Aug 1988
  571.  
  572.       ================================================================ 
  573.       DATABASE IN C: By Arnold Cherdak
  574.       ================================================================ 
  575.  
  576.            The binary search is just about the most efficient way to
  577.       search a linear, sorted list whether that list is in memory as
  578.       implied by LISTING 1, or in a file.  After all, each time a
  579.       decision is made to search in one half of the places (records)
  580.       available, the other half is excluded and doesn't have to be
  581.       searched.  You can narrow the options quite rapidly with this
  582.       technique.
  583.  
  584.      
  585.            Note that if the database is in chronological order and the
  586.       date-time the record was added to the database is included in each
  587.       record, then a binary search of the file based on date-time can be
  588.       performed without the use of an index.  
  589.       
  590.       
  591.        EXERCISE:    Write a function to create an index list of the
  592.                     FAMILIES file in memory.  Use a structure for the
  593.                     index list element as follows:
  594.       
  595.                     struct {
  596.                            int recaddr;  /* FAMILIES record pointer */     
  597.                     char key[25]; /* street name */
  598.                             } index_rec;
  599.       
  600.                     Adapt the binary search function shown in LISTING 1
  601.                     to your index.
  602.       
  603.                     Write a k(x) function to return the key given a list   
  604.                     position.
  605.  
  606.       
  607.                    Write a program to print the Main Street List using
  608.                    the above functions, and the index list in memory,
  609.                    and any other functions you might need to get all
  610.                    twelve Main Street records in the file.
  611.       
  612.  
  613.  
  614.      C News 1-10                Page 13                   09 Aug 1988
  615.  
  616.       ================================================================ 
  617.       DATABASE IN C: By Arnold Cherdak
  618.       ================================================================ 
  619.       
  620.                ---------------------------------------------
  621.                             DATABASE 401 -- TREES
  622.    
  623.                         
  624.            OKAY!  You're on your way to becoming an expert or at least
  625.       more familiar with the subject of programming database search 
  626.       routines.  Next, with trees.
  627.       
  628.       What's a tree? You ask...
  629.       
  630.            Well, a tree offers a way to organize data to make it easier to 
  631.       search for particular data elements.  A tree is a data structure 
  632.       constructed of nodes and linkages among nodes (the notion of the
  633.       linkage as distinct from the node isn't really right but I'll correct
  634.       that in just a bit).  A tree is an orderly arrangement of nodes
  635.       interconnected by linkages.  In C parlance, the node is a structure
  636.       containing a value or a set of values and two or more pointers to
  637.       structures of the same type as the node.
  638.  
  639.      
  640.               struct node {
  641.                           char key[25];
  642.                           int recno;
  643.                           struct node *lptr;
  644.                           struct node *rptr;
  645.                           };
  646.       
  647.            The structure depicted above may be created using the calloc()
  648.       function as described in K&R.  Note that the linkages among nodes
  649.       are not separate entities but are in truth the pointers contained   
  650.       within the node structure.  In the above case, lptr and rptr are 
  651.       the linkages between a node and its adjacent nodes in the tree. 
  652.      
  653.            A tree is created at its root and it grows from there.  In 
  654.       this case, a root is a pointer to a node.  Define the pointer 
  655.       thus:
  656.                           struct node *root;
  657.       
  658.            Now, create the first node using calloc() which returns a 
  659.       pointer value.  Assign that pointer value to root using a cast to
  660.       get the pointer type correct.
  661.       
  662.            root = (struct node *) calloc(1, sizeof(struct node));       
  663.  
  664.            Note that root->lptr and root->rptr are of the same type as
  665.       the variable, root, and that they may be used with calloc() in
  666.       the same way to point or link from one node to another in the tree.
  667.  
  668.       C News 1-10                Page 14                   09 Aug 1988
  669.  
  670.       ================================================================ 
  671.       DATABASE IN C: By Arnold Cherdak
  672.       ================================================================ 
  673.       
  674.          root->lptr = (struct node *) calloc(1, sizeof(struct node));      
  675.  
  676.            In this way, new nodes are generated and linked to previously
  677.        generated nodes, hence to the root of the tree.  If one wanted to
  678.        reach any node in the tree, it is a relatively straightforward
  679.        matter to start at the root and follow the pointers until the
  680.        desired node is reached.  Welllll...it's a bit more difficult
  681.        than that but not a lot more.  However, it does get somewhat
  682.        complex and, as I promised earlier, I'm going to keep this as
  683.        simple as I can for you and for me.
  684.       
  685.          A tree has a visual appearance similar to Figure 1.
  686.  
  687.             -------------------------------------------------      
  688.                      FIGURE 1.  Basic Tree Structure
  689.       
  690.                                    |pointer to root node
  691.                                    |
  692.                                  Root
  693.                                  Node
  694.                                  /   \ 
  695.                                /       \
  696.                             Node1      Node2
  697.                             / \         / \
  698.                           /     \     /     \
  699.                       Node3   Node4  Node5   Node6
  700.                       / \       / \  / \     / \      
  701.  
  702.                       etc................
  703.  
  704.             -------------------------------------------------
  705.  
  706.            The tree of FIGURE 1 is called a Binary Tree because each node
  707.        is linked to two other nodes further down in the tree.  If each
  708.        node contains a key and a corresponding record's file address,
  709.        then the tree can represent the entire index to the database
  710.        file.  Furthermore, if the keys and addresses are installed in 
  711.        the nodes with the rule that keys having values lower than the 
  712.        value of a key in a node can only be installed in a new node
  713.        pointed to by a left-directed pointer and higher valued keys go
  714.        into nodes pointed to by right-directed pointers, then the tree     
  715.        can be searched for a key value with similar results to a binary
  716.        search on a linear, sorted list or file.  WHEW!  That was a
  717.        mouthful.  
  718.       
  719.            I don't offer proof of the above but if you assume that the
  720.        root is very close to having the middle or median value key in
  721.        the database, then it becomes apparent that if you search for a
  722.       C News 1-10                Page 15                   09 Aug 1988
  723.  
  724.       ================================================================ 
  725.       DATABASE IN C: By Arnold Cherdak
  726.       ================================================================ 
  727.  
  728.       specific key value starting at the root, and, for a key value 
  729.       lower than the root key value, you follow the left-directed
  730.       pointer, you will never have to follow any pointers linked to the
  731.       right-directed pointer.  This is directly analogous to the binary
  732.       search described above.
  733.       
  734.            Well, that's all well and good but what does it do for me and
  735.       you?  The value is not in the useful but simple binary tree.  It
  736.       is in what are called Multiway trees or trees that have more than
  737.       one key and more than two pointers per node.  These are also
  738.       called B_Trees.  These trees are searched in much the same manner
  739.       the binary tree is searched with the notable exception that at
  740.       each node containing more than two pointers to lower level nodes
  741.       in the tree, there are more than two paths that can be followed
  742.       and an appropriate number of decisions to be made to select the
  743.       right path.
  744.  
  745.             A special case of a B_Tree, a B+_Tree, has special properties
  746.       which, in addition to the capability to be searched rapidly for a 
  747.       random selection of key values, also lends itself to linear 
  748.       searching.  Well, this is getting close to my maximum confusion
  749.       index so I'll simply state that there is reason for wanting to
  750.       use structures having this kind of complexity and that reason is
  751.       search performance compared with some of the other search 
  752.       techniques mentioned above.
  753.       
  754.            Needless to say, programming such structures and the programs
  755.       needed to maintain and search them is not trivial.  It is probably
  756.       wise to decide whether it is more important to solve the database
  757.       problem for yourself or to pursue the education needed to create
  758.       such programs.  For me, the choice is obvious.  I'll take the easy
  759.       way and let someone else do it for me.
  760.       
  761.            If you're just dying to learn all you can about trees then try 
  762.       some of the books listed in the bibliography at the end of this
  763.       article.  For present purposes, I refer you to the .ARC file, 
  764.       BPLUS11.ARC, included with this article.  This is a shareware 
  765.       package that does all this tree stuff for you and makes using trees
  766.       for database applications a whole lot easier.  This isn't the only
  767.       such package.  There are lots of records management support packages
  768.       available in shareware and as regular products for sale that use the
  769.       tree as well as other methods.
  770.       
  771.            The following is excerpted from the B-PLUS documentation 
  772.       contained in the ARC file.  It would be appropriate to read it all
  773.       before you use the package.  The documentation file also includes a
  774.       description of the parameters for each function as well as its
  775.       source code.  Note that I have version 1.1 which isn't quite right
  776.       C News 1-10                Page 16                   09 Aug 1988
  777.  
  778.       ================================================================ 
  779.       DATABASE IN C: By Arnold Cherdak
  780.       ================================================================ 
  781.  
  782.       for Turbo-C, version 1.5.  I spoke with Larry Hunter whose company
  783.       markets this product, and he told me that BPLUS version 1.1A solves
  784.       that and another problem.  It's available on COMPUSERVE, now.  In
  785.       the meantime, Larry told me how to fix the Turbo-C 1.5 compatibility
  786.       problem which I did.  I've included a brief note on this along with
  787.       the BPLUS11.ARC file in file, BPLUS11.NOT.
  788.       
  789.            "The B-PLUS File Indexing Module contains twelve 
  790.             functions that handle the retrieval of data records
  791.             by key value.  The keys that are used to locate records
  792.             are null terminated strings.  The data structures and
  793.             constants that are used are defined in the header file
  794.             bplus.h."  
  795.        
  796.              The following are the names and descriptions of the twelve
  797.       functions:
  798.       
  799.       open_index:   The open_index function is used to open and 
  800.                     initialize an existing index file specified by
  801.                     name and prepares the file for subsequent reading
  802.                     or writing.
  803.       
  804.        
  805.       make_index:   The make_index function is used to create and
  806.                     initialize a new index file specified by name and
  807.                     to prepare the file for subsequent reading or 
  808.                     writing.
  809.       
  810.       close_index:  The close_index file function clears the internal
  811.                     cache buffer and closes the specified index file.     
  812.   
  813.       find_key:     The find_key function searches the index file for
  814.                     the key value.
  815.       
  816.       locate_key:   The locate key function searches the index file
  817.                     for the first key value which is equal to or
  818.                     greater than a specified key.
  819.       
  820.       add_key:      The add_key function adds new entries to the index 
  821.                     file.
  822.       
  823.       delete_key:   The delete_key function deletes entries in the 
  824.                     index file.
  825.       
  826.       first_key:    The first_key function positions the index file
  827.                     pointer to the beginning of the index file.  The 
  828.                     function next_key can then be used to list the file in
  829.                     key order.
  830.       C News 1-10                Page 17                   09 Aug 1988
  831.  
  832.       ================================================================ 
  833.       DATABASE IN C: By Arnold Cherdak
  834.       ================================================================ 
  835.       
  836.       last_key:     The last_key function positions the index file
  837.                     pointer at the end of the index file.  The 
  838.                     function previous_key can then be used to list the 
  839.                     file in reverse key order.
  840.       
  841.       next_key:     The next_key function returns the next entry in
  842.                     the index file.  Before next_key is called, the
  843.                     index file pointer should be positioned by the
  844.                     function first_key, find_key, or locate_key.
  845.                     Next_key can be used to locate the desired data 
  846.                     record when duplicate keys are allowed.  Another
  847.                     use is to process files, sequentially.
  848.       
  849.       prev_key:     The prev_key function returns the previous entry
  850.                     in the index file.  Before prev_key is called, the 
  851.                     index file pointer should be positioned by the
  852.                     function last_key, find_key, or locate_key. 
  853.                     Prev_key can be used to process files sequentially 
  854.                     in reverse order.
  855.       
  856.       find_exact:   The find_exact function searches the index file
  857.                     for a specific key and data record position.       
  858.  
  859.       
  860.              After playing with BPLUS for a while, I find that the only
  861.       real criticism I have is that there isn't a tree-search function
  862.       for multiple identical keys.  The example program called DTEST.C
  863.       that I've provided, prints out the Main Street Report, but it 
  864.       searches linearly through the index file to find the 12 Main
  865.       Street records.  There are other ways to use the BPLUS functions
  866.       but this is the way I found first to make the example work.  Just
  867.       the same, BPLUS works well.
  868.  
  869.             -------------------------------------------------
  870.                               BIBLIOGRAPHY
  871.       
  872.       Borland International, Inc., Turbo C documentation, Version 1.5,
  873.       1988.
  874.       
  875.       Borland International, Inc., "Turbo Pascal Database Toolbox".       
  876.       Hunt, "The C Toolbox", Addison-Wesley, 1985.
  877.       
  878.       Hursch and Hursch, "SQL The Structured Query Language", TAB 
  879.       Books, 1988.
  880.       
  881.       Kernighan and Ritchie, "The C Programming Language", Prentice-
  882.       Hall, 1978.
  883.       
  884.       C News 1-10                Page 18                   09 Aug 1988
  885.  
  886.       ================================================================ 
  887.       DATABASE IN C: By Arnold Cherdak
  888.       ================================================================ 
  889.  
  890.       Schwaderer, "C Wizard's Programming Reference", Wiley Press,
  891.       1985.
  892.       
  893.       SoftCraft, Inc., "Btrieve User's Guide"
  894.       
  895.       Tennenbaum and Augenstein, "Data Structures Using Pascal", Second
  896.       Ed., Prentice-Hall, 1986.
  897.       
  898.       Tsichritzis and Lochovsky, "Data Base Management Systems",
  899.       Academic Press, 1977.
  900.       
  901.       Wirth, "Algorithms + Data Structures = Programs", Prentice Hall,
  902.       1976.
  903.        
  904.  
  905.       C News 1-10                Page 19                   09 Aug 1988  
  906.       ================================================================ 
  907.       Latest Versions of Commercial/PD Software. 
  908.       ================================================================ 
  909.  
  910.        Compilers:          Ver:            
  911.        ---------           ---- 
  912.  
  913.        Microsoft C         5.10 
  914.        QuickC              1.01 
  915.  
  916.        TurboC              1.5       /* With a rumored 2.0 out */ 
  917.        Datalight           2.1
  918.        MIX C               ? 
  919.        PowerC              ? 
  920.        Lattice C           ? 
  921.        Watcom              6.0 
  922.  
  923.       C News 1-10                Page 20                   09 Aug 1988  
  924.       ================================================================ 
  925.       ARTICLE SUBMISSION STANDARDS AND ADDRESSES 
  926.       ================================================================ 
  927.  
  928.    
  929.            As I have repeatedly stated in this newsletter and previous   
  930.       issues, I would like to see user-submitted articles, reviews or   
  931.       questions.  Listed below are the standards that should be   
  932.       followed to make my job easier as an editor.   
  933.    
  934.    
  935.           - Articles should be submitted in a ASCII non-formatted   
  936.             file.  (Margins 0-65 PLEASE) 
  937.    
  938.           - If the article include code fragments as examples. Then   
  939.             you can include the entire source file if you like for    
  940.             inclusion with the newsletter.   
  941.    
  942.           - Book or magazine reviews should follow the same format,   
  943.             that is outlined in this issue.  The publisher, author,   
  944.             title, and ISBN number are a must.     
  945.    
  946.           - Compiler/and or product reviews, should include the   
  947.             version number and manufacture.  If possible, reviews   
  948.             should include a sample program with benchmarks.   
  949.    
  950.        
  951.             If you have any questions you can contact me at the   
  952.       address's included on the next page.   
  953.    
  954.       C News 1-10                Page 21                   09 Aug 1988  
  955.       ================================================================ 
  956.       ADDRESSES 
  957.       ================================================================ 
  958.    
  959.             The C BBS is located at:   
  960.    
  961.               C BBS   
  962.               % BCL Limited   
  963.               P.O. Box 9162   
  964.               McLean VA, 22102   
  965.    
  966.    
  967.             or you can send netmail to:   
  968.    
  969.    
  970.             1:109/713    
  971.    
  972.    
  973.    
  974.    
  975.   
  976.       C News 1-10                Page 22                   15 Jul 1988  
  977.       ================================================================ 
  978.                                  INDEX              
  979.       ================================================================ 
  980.    
  981.       Subject:                                          Issue:   
  982.    
  983.       Articles:   
  984.    
  985.       Additional Comments of Filename Wild..             6  
  986.       Beginning C Functions                              7  
  987.       C Spot Run: A User Supported Library               7
  988.       Database Design in C                              10  
  989.       Filename Wildcard Expansion in MSC                 4   
  990.       Integrated Environment: TC & QC                    5   
  991.       Programming the Hercules Graphics Card             8 
  992.       Programming the Hercules Graphics Card: Part 2     9
  993.       Talking with a Fossil                              5   
  994.       TurboC and Interrupts: A few Questions             2   
  995.          
  996.       Book Reviews:   
  997.                
  998.       C Chest: and other treasures.                      6  
  999.       C Database Development                             1   
  1000.       C Programming Guide                                1   
  1001.       C Programming Language                             1   
  1002.       C Programmer's Guide to Serial Communications      3   
  1003.       C Programmer's Library                             1   
  1004.       C Primer Plus                                      1   
  1005.       C the Complete Reference                           2   
  1006.       Crafting C Tools for the IBM PC                    2   
  1007.       Learning to Program in C                           1   
  1008.       Microsoft C Programming on the IBM PC              1   
  1009.       MS-DOS Developer's Guide                           4   
  1010.       Programming in Windows                             3
  1011.       QuickC Programming for the IBM                    10    
  1012.       Reliable Data Structures in C                      1   
  1013.       TurboC: Memory Resident Utilities                  5   
  1014.       TurboC Programmer's Reference Book                 2   
  1015.    
  1016.     
  1017.       Compilers:    
  1018.    
  1019.       QuickC                                             1  
  1020.         
  1021.       Software Reviews:    
  1022.      
  1023.       Bplus11.arc                                        3   
  1024.       C_Dates.arc                                        4   
  1025.       Cdate.arc                                          4   
  1026.       Casm.arc                                           3   
  1027.       C-subr.arc                                         4
  1028.       C News 1-10                Page 23                   09 Aug 1988
  1029.  
  1030.       ================================================================ 
  1031.                                   INDEX
  1032.       ================================================================ 
  1033.    
  1034.       Docu.arc                                           3   
  1035.       Ezwind.arc                                         8 
  1036.       Jcl-src.arc                                        4   
  1037.       Mscpopup.arc                                       3   
  1038.       Ndmake41.arc                                       4   
  1039.       Nuc-subr.arc                                       3  
  1040.       Prndoc.arc                                         6   
  1041.       Sed.arc                                            6   
  1042.       Shift_c.arc                                        4  
  1043.       Sysact11.arc                                       4   
  1044.       Tp_to_qc.arc                                       3   
  1045.       Xenixarc.arc                                       4   
  1046.    
  1047.       C News 1-10                Page 24                   09 Aug 1988   
  1048.         
  1049.       ================================================================   
  1050.                             DISTRIBUTION POINTS   
  1051.       ================================================================   
  1052.    
  1053.    
  1054.       Board Name               Number         Net/Node       Sysop   
  1055.    
  1056.       United States   
  1057.    
  1058.       C BBS               (703) 644-6478      1:109/713      Barry Lynch   
  1059.       Burke, VA   
  1060.    
  1061.       Jaz C-Scape         (904) 724-1377      1:112/1027     Tom Evans   
  1062.       Jacksonville, FL   
  1063.  
  1064.    
  1065.       Eastern C Board     (201) 247-6748      1:107/335      Todd Lehr   
  1066.    
  1067.       OTHER BOARDS THAT CARRY C NEWS:
  1068.  
  1069.       Exec-PC             (414) 964-5160        ..           Bob Mahoney
  1070.       Milwaukee, WI
  1071.  
  1072.       TAMIAMI             (813) 793-2392                     Gerhard Barth
  1073.       Naples, FL
  1074.        
  1075.       Sound of Music      (516) 536-8723(2400)               Paul Waldinger
  1076.                           (516) 536-6819(9600 Hayes V)   
  1077.    
  1078.       Canada   
  1079.    
  1080.       Another BBS System  (416) 465-7752      1:148/208      Mark Bowman   
  1081.       Toronto, Canada   
  1082.    
  1083.       Europe   
  1084.    
  1085.       Fido_N1_1               31-8350-37156     2:500/1        Henk Wevers 
  1086.  
  1087.       The Netherlands   
  1088.    
  1089.       Australia   
  1090.    
  1091.       Alpha-Centuri BBS   011-61-3-874-3559    3:632/348     David Nugent  
  1092.  
  1093.    
  1094.    
  1095.       C News 1-10                Page 25                   09 Aug 1988  
  1096.       ================================================================ 
  1097.       USER RESPONSE FORM 
  1098.       ================================================================ 
  1099.    
  1100.        This form will be included as a regular feature in all future   
  1101.       issues of C NEWS.   
  1102.    
  1103.    
  1104.    
  1105.        What did you think of the content of this Issue?  _____________   
  1106.         
  1107.        _______________________________________________________________   
  1108.   
  1109.        What improvements can you think of that would make C News a   
  1110.        better tool for the C Community?   
  1111.    
  1112.        _______________________________________________________________   
  1113.  
  1114.        _______________________________________________________________   
  1115.    
  1116.    
  1117.        What is your favorite section or sections?  ___________________   
  1118.    
  1119.        _______________________________________________________________   
  1120.    
  1121.    
  1122.        What don't you like about C News?  ____________________________   
  1123.    
  1124.        _______________________________________________________________   
  1125.    
  1126.    
  1127.        Additional Comments:  _________________________________________   
  1128.    
  1129.        _______________________________________________________________   
  1130.    
  1131.        _______________________________________________________________   
  1132.    
  1133.        _______________________________________________________________   
  1134.  
  1135.    
  1136.   
  1137.   
  1138.   
  1139.